/*
 * Copyright (c) 2020, 2023, 3044483124@qq.com All rights reserved.
 *
 */
package cn.itcast;

import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * <p>Project: JavaStudy - Sum100
 * <p>Powered by jiangbo On 2023-01-03
 * 10:02:01
 * <p>Created by IntelliJ IDEA
 *
 * @author jiangbo [3044483124@qq.com]
 * @version 1.0
 * @since 8/17
 */
public class Sum100 {
    public static void main(String[] args) {
        Set<String> set = new HashSet<String>();
        while (set.size() != 11) {
            String str = getStr();
            if (sum(str) == 100) {
                set.add(str);
            }
        }
//计算完成之后输出
        for (String s : set) {
            System.out.printf("%s = 100%n", s);
        }
    }
    public static int sum(String str) {
        int sum = 0;
        Pattern pattern = Pattern.compile("-?\\d+");
        Matcher matcher = pattern.matcher(str);
        while (matcher.find()) {
            sum += Integer.parseInt(matcher.group());
        }
        return sum;
    }
    public static String getStr() {
        Random rand = new Random();
        StringBuilder sbu = new StringBuilder();
        String[] ops = {"", "+", "-"};
        for (int i = 1; i < 9; i++) {
            sbu.append(i + ops[rand.nextInt(ops.length)]);
        }
        sbu.append(9);
        return sbu.toString();
    }

    }


